package de.mhus.lib.mandala;

import java.util.List;

import de.mhus.lib.mandala.functions.FunctionCall;

public class UiUtil {

	@SuppressWarnings("unchecked")
	public static void renderAsGetter(Object o, Component parent, Response out) {
		if (o == null) {
			out.print("null");
		} else
		if ( o instanceof Object[]) {
			for (Object oo : (Object[])o) {
				UiUtil.renderAsGetter(oo, parent, out);
			}
		} else
		if ( o instanceof List<?>) {
			for (Object oo : (List<Object>)o) {
				UiUtil.renderAsGetter(oo, parent, out);
			}
		} else
		if (o instanceof FunctionCall) {
			((FunctionCall)o).doRender(parent, out);
		} else
		if (o instanceof Element) {
			((Element)o).renderElementCall(out);
		} else
			out.print(o.toString());
	}

	@SuppressWarnings("unchecked")
	public static void renderAsFunctions(Object o, Component parent, Response out) {
		if (o == null) {
			out.print("null");
		} else
		if ( o instanceof Object[]) {
			for (Object oo : (Object[])o) {
				UiUtil.renderAsFunctions(oo, parent, out);
			}
		} else
		if ( o instanceof List<?>) {
			for (Object oo : (List<Object>)o) {
				UiUtil.renderAsFunctions(oo, parent, out);
			}
		} else
		if (o instanceof FunctionCall) {
			((FunctionCall)o).doRender(parent, out);
		} else
		if (o instanceof Element) {
			((Element)o).renderElementName(out);
		} else
			out.print(o.toString());
	}
	
}
